package com.fuchuang.seckillsystem.utils;

import org.drools.decisiontable.InputType;
import org.drools.decisiontable.SpreadsheetCompiler;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 将xls解析成drl文件
 */
public class KieSessionUtils {
    private KieSessionUtils() {
    }
    
    // 把xls文件解析为String
    public static String getDRL(String realPath, String fileName) throws IOException {
        File file = new File(realPath + fileName); // 例如：C:\\abc.xls
        InputStream is = new FileInputStream(file);
        SpreadsheetCompiler compiler = new SpreadsheetCompiler();
        String drl = compiler.compile(is, InputType.XLS);
        int i = fileName.indexOf('.');
        String resultName = fileName.substring(0, i) + ".drl";
        FileOutputStream fos = new FileOutputStream(realPath + resultName);
        fos.write(drl.getBytes(StandardCharsets.UTF_8));
        fos.close();
        return resultName;
    }
    
}